﻿using System;
using System.IO;
using UnityEngine;

// Token: 0x02000426 RID: 1062
[RequireComponent(typeof(Camera))]
public class RendCapCamera : MonoBehaviour
{
	// Token: 0x06001A3F RID: 6719 RVA: 0x000A7E30 File Offset: 0x000A6030
	private void Awake()
	{
		this.capCamera = base.GetComponent<Camera>();
	}

	// Token: 0x06001A40 RID: 6720 RVA: 0x000A7E40 File Offset: 0x000A6040
	private void Start()
	{
		this.capCamera.enabled = false;
	}

	// Token: 0x06001A41 RID: 6721 RVA: 0x000A7E50 File Offset: 0x000A6050
	private void OnDestroy()
	{
	}

	// Token: 0x06001A42 RID: 6722 RVA: 0x000A7E54 File Offset: 0x000A6054
	public Texture2D Capture()
	{
		this.capCamera.enabled = true;
		int num = this.saveWidth * this.superSize;
		int num2 = this.saveHeight * this.superSize;
		RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 24);
		this.capCamera.targetTexture = temporary;
		this.capCamera.Render();
		RenderTexture.active = temporary;
		Texture2D texture2D = new Texture2D(num, num2, TextureFormat.RGB24, false);
		texture2D.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
		texture2D.Apply();
		TextureScale.Bilinear(texture2D, this.saveWidth, this.saveHeight);
		this.capCamera.targetTexture = null;
		RenderTexture.ReleaseTemporary(temporary);
		this.capCamera.enabled = false;
		return texture2D;
	}

	// Token: 0x06001A43 RID: 6723 RVA: 0x000A7F0C File Offset: 0x000A610C
	public void Save(string file)
	{
		this.SavePNG(file, this.Capture());
	}

	// Token: 0x06001A44 RID: 6724 RVA: 0x000A7F1C File Offset: 0x000A611C
	public void Save()
	{
		DateTime now = DateTime.Now;
		string file = string.Concat(new object[]
		{
			now.Year,
			"年",
			now.Month,
			"月",
			now.Day,
			"日",
			now.Hour,
			"時",
			now.Minute,
			"分",
			now.Second,
			"秒",
			now.Millisecond.ToString("0000"),
			".png"
		});
		this.SavePNG(file, this.Capture());
	}

	// Token: 0x06001A45 RID: 6725 RVA: 0x000A7FF8 File Offset: 0x000A61F8
	private void SavePNG(string file, Texture2D tex)
	{
		byte[] buffer = tex.EncodeToPNG();
		using (FileStream fileStream = new FileStream(file, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
			{
				binaryWriter.Write(buffer);
				binaryWriter.Close();
			}
			fileStream.Close();
		}
	}

	// Token: 0x04001D21 RID: 7457
	private Camera capCamera;

	// Token: 0x04001D22 RID: 7458
	[SerializeField]
	private int superSize = 2;

	// Token: 0x04001D23 RID: 7459
	[SerializeField]
	private int saveWidth = 252;

	// Token: 0x04001D24 RID: 7460
	[SerializeField]
	private int saveHeight = 252;
}
